﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chowpoo.Sql;
using CourseSystem.Core.Entities;
using CourseSystem.Core.SqlServerDAL;

namespace CourseSystem.Core.BLL
{
    public class ClassBLL : CommonBLL<ClassInfo, ClassDAL>
    {
        public static List<ClassInfo> GetBySubId(int id)
        {
            using (var dal = new ClassDAL(Settings.ConnectionName))
            {
                var re = dal.Select(o => o.SubjectId == id);
                return re;
            }
        }

        public static IQueryable<ClassInfo> GetList(int id)
        {
            using (var dal = new ClassDAL(Settings.ConnectionName))
            {
                var re = dal.SelectQueryable(o => o.SubjectId == id);
                return re;
            }
        }

        public static ClassInfo Get(int value)
        {
            using (var dal = new ClassDAL(Settings.ConnectionName))
            {
                var re = dal.SelectSingle(o => o.Id == value);
                return re;
            }
        }

        public static ClassInfo GetByImport(string className, string subjectName, string departName, string collegeName)
        {
            using (var dal = new ClassDAL(Settings.ConnectionName))
            {
                var re = dal.SelectSingle(o => o.ClassName == className && 
                    o.SubjectInfo.Name == subjectName &&
                    o.SubjectInfo.DepartmentInfo.Name == departName &&
                    o.SubjectInfo.DepartmentInfo.CollegeInfo.Name == collegeName);
                return re;
            }
        }

        public static bool Del(int id)
        {
            using (var dal = new ClassDAL())
            {
                return dal.Delete(o => o.Id == id) != null;
            }
        }
    }
}
